import host from './env.js'

//基础请求方法
function request(url,method,data,){
	return new Promise((resolve,reject)=>{
		uni.request({
			url:host+url,
			method,// "method":method
			data,
			success: (res) => {
				//将成功返回的结果封装成promise对象
				if(res.statusCode==200){
					resolve(res.data);
				}else{
					reject(res);
				}
				
			},
			fail:err=>{
				reject(err);
			}
		})
	});
}

export default{
	post(url,data){
		return request(url,"POST",data);
	},
	get(url,data){
		return request(url,"GET",data);
	},
	put(url,data){
		return request(url,"PUT",data);
	},
	delete(url,data){
		return request(url,"DELETE",data);
	}
}